<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var zhanghao = "a356";

        if (zhanghao.trim() == "") {
            console.log("请输入你的想要的名称");
        } else if (!/^[A-Za-z]/.test(zhanghao)) {
            console.log("请以以字母开头");
        } else if (zhanghao.length < 3 || zhanghao.length > 18) {
            console.log("长度应在3-18位");
        } else if (/[\._-]$/.test(zhanghao)) {
            console.log("不能以._-特殊符号结尾");
        } else if (/([\._-]){2,}/.test(zhanghao)) {
            console.log("不能以._-出现连续的");
        }
        // else if (/([A-Za-z]+[0-9]*[\._-]*[])*$/.test(zhanghao)) {
        //     p.innerHTML = "只能用.-_三种特殊字符"
        // }
        else {
            console.log("格式正确");
        }

    </script>
</body>

</html>